package com.sda.huoshui.util

import com.blankj.utilcode.util.TimeUtils
import java.text.SimpleDateFormat
import java.util.*


class DateTools {

    companion object {

        //获取日期所在月份的最后一天
        fun getDateLast(dateString: String):String{
            val a = TimeUtils.string2Millis(dateString, SimpleDateFormat("yyyy-MM", Locale.getDefault()))
            var dateOne = TimeUtils.millis2String( a, SimpleDateFormat("yyyy-MM", Locale.getDefault()))

            var yue = TimeUtils.date2String(Date(a), SimpleDateFormat("MM", Locale.getDefault()))
            if (yue.startsWith("0")){
                yue = yue.replace("0","")
            }
            dateOne = dateOne+"-" + getDateOfDayNumber(yue,TimeUtils.isLeapYear(dateString,SimpleDateFormat("yyyy-MM", Locale.getDefault())))
            return dateOne
        }

        //获取日期所在月份的第一天
        fun getDateOnce(dateString: String):String{
            val a = TimeUtils.string2Millis(dateString, SimpleDateFormat("yyyy-MM", Locale.getDefault()))
            val dateOne = TimeUtils.millis2String( a, SimpleDateFormat("yyyy-MM", Locale.getDefault()))
            return "$dateOne-01"
        }

        //获取当月份的天数
        fun getDateOfDayNumber(yue:String,isRue:Boolean):String{
            var dayNumber = ""
            if (yue == "1" || yue =="3"|| yue =="5"|| yue =="7"|| yue =="8"|| yue =="10"|| yue =="12"){
                dayNumber = "31"
            }else if (yue == "2"){
                if (isRue){
                    dayNumber = "29"
                }else{
                    dayNumber = "28"
                }
            }else{
                dayNumber = "30"
            }
            return dayNumber
        }

        //获取日历填充数量
        fun getDateOfOneNumber(millis:Long):Int{
            return when(TimeUtils.getChineseWeek(millis)){
                "周一" -> 1
                "周二" -> 2
                "周三" -> 3
                "周四" -> 4
                "周五" -> 5
                "周六" -> 6
                else -> 0
            }
        }

        fun getDayByMillis(millis:Long):String{
            return TimeUtils.millis2String(millis,SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()))
        }
    }

}
